package com.xnck.demo.activitidemo.helper.impl;

import com.xnck.demo.activitidemo.helper.SubProcessHelper;
import org.activiti.engine.delegate.DelegateExecution;

import java.util.ArrayList;
import java.util.List;

public class SubProcessHelperImpl implements SubProcessHelper {

    @Override
    public List<String> getUserNames() {
        List<String> userNames = new ArrayList<>();
        userNames.add("test001");
        userNames.add("test002");
        userNames.add("test003");
        return userNames;
    }

    @Override
    public boolean isComplete(DelegateExecution execution) {
        Integer completeInstCount = (Integer) execution.getVariable("nrOfCompletedInstances");
        Integer instCount = (Integer) execution.getVariable("nrOfInstances");
//        int agreeCount = 0;
//        if (null != completeInstCount) {
//            for (int i = 0; i < completeInstCount; i++) {
//                Object opinionObj = execution.getVariable("opinion" + (i + 1));
//                if (null != opinionObj && "agree".equals(opinionObj.toString())) {
//                    agreeCount++;
//                }
//            }
//            if (((float)instCount / 2) < agreeCount) {
//                return true;
//            }
//        }
//        return instCount.equals(completeInstCount);
        return completeInstCount > 1;
    }
}
